package com.bw.controller;

import com.bw.domain.SysGoods;
import com.bw.service.SysBrandService;
import com.bw.service.SysGoodsService;
import com.bw.utils.common.Result;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author bobo棒
 * @date 2023年11月21日 15:55
 */

@RequestMapping("goods")
@RestController
public class GoodsController {
    @Autowired
    SysGoodsService sysGoodsService;
    @Autowired
    SysBrandService sysBrandService;


    @RequestMapping("list")
    public Result list(@RequestBody  SysGoods sysGoods, @RequestParam(defaultValue = "1") Integer pageNum){
        PageHelper.startPage(pageNum,3);
        List<SysGoods> goods = sysGoodsService.list(sysGoods);
        PageInfo<SysGoods> info = new PageInfo<>(goods);
        return Result.success(info);
    }


    @RequestMapping("delById")
    public Result delById(Integer id){
        boolean b = sysGoodsService.removeById(id);
        return b?Result.success():Result.fail();
    }
    @RequestMapping("brandsList")
    public Result brandsList(){
        return Result.success(sysBrandService.list());
    }
}
